package bidsanity



import grails.test.mixin.*
import org.junit.*

/**
 * See the API for {@link grails.test.mixin.services.ServiceUnitTestMixin} for usage instructions
 */
@TestFor(ListingService)
@Mock([Customer, Listing, Bid, CustomerService])
class ListingServiceTests {
    def customerService = new CustomerService()

    void testCreateListing(){
        Assert.assertNotNull(customerService)
        def s = customerService.createCustomer(emailAddress: 'seller@example.org', password: "testing")
        Assert.assertNotNull(s.id)
        def list = service.createListing(
                name: 'TestListing',
                endDate: new Date() + 10,
                startingBidPrice: 1.0D,
                description: 'a test listing',
                sellerId: s.id)
        Assert.assertNotNull(list)
        Assert.assertNotNull(list.id)
        Assert.assertFalse(list.hasErrors())
    }

    void testCreateBadListing(){
        Assert.assertNotNull(customerService)
        def s = customerService.createCustomer(emailAddress: 'seller@example.org', password: "testing")
        Assert.assertNotNull(s.id)
        def list = service.createListing(
                name: 'TestListing',
                endDate: new Date() - 10,
                startingBidPrice: 0.0D,
                description: 'a test listing',
                sellerId: s.id)
        Assert.assertNotNull(list)
        Assert.assertTrue(list.hasErrors())
    }
}
